<template>
  <div>
    <div class="deleStatus" @click="show = true">
      消息
      <img src="@/assets/deleMsg.png" alt="" class="deleImg" />
    </div>
    <div class="wrap">
      <div class="item" @click="jumpPraiseList">
        <div class="leftIconWrap">
          <img src="@/assets/msgItem1.png" alt="" class="icon" />
          <em class="leftText">赞</em>
        </div>
        <div class="rightIconWrap">
          <em class="number" v-if="resMsgReadNum.likeMsgNum > 0">{{
            resMsgReadNum.likeMsgNum
          }}</em>
          <img src="@/assets/rightArrow.png" alt="" class="arrow" />
        </div>
      </div>
      <div class="item" @click="jumpCommentList">
        <div class="leftIconWrap">
          <img src="@/assets/msgItem2.png" alt="" class="icon" />
          <em class="leftText">评论</em>
        </div>
        <div class="rightIconWrap">
          <em class="number" v-if="resMsgReadNum.commentMsgNum > 0">{{
            resMsgReadNum.commentMsgNum
          }}</em>
          <img src="@/assets/rightArrow.png" alt="" class="arrow" />
        </div>
      </div>
      <div class="item" @click="jumpSystemList">
        <div class="leftIconWrap">
          <img src="@/assets/msgItem3.png" alt="" class="icon" />
          <em class="leftText">系统消息</em>
        </div>
        <div class="rightIconWrap">
          <em class="number" v-if="resMsgReadNum.sysMsgNum > 0">{{
            resMsgReadNum.sysMsgNum
          }}</em>
          <img src="@/assets/rightArrow.png" alt="" class="arrow" />
        </div>
      </div>
    </div>
    <!-- 遮罩层-清空消息： -->
    <div class="maskWrap" v-if="show">
      <div class="maskBg" @click="show = false"></div>
      <div class="chooseNumWrap">
        <div class="optionsItem" @click="getClearMessageUnReadNum(0)">全部已读</div>
        <div class="optionsItem" @click="getClearMessage">清空消息</div>
        <div class="optionsItem dele" @click="show = false">取消</div>
      </div>
    </div>
  </div>
</template>

<script>
import { Switch, Dialog } from "vant";
import {
  aipGetMessageUnReadNum,
  apiClearMessageUnReadNum,
  apiClearMessage,
} from "@/request/api"; // api接口
export default {
  name: "App",
  data() {
    return {
      show: false,
      resMsgReadNum: "",
    };
  },
  mounted() {
    this.getMessageUnReadNum();
    document.querySelector("body").setAttribute("style", "background-color:#F2F4FA");
  },
  methods: {
    //获取未读消息数量：
    getMessageUnReadNum() {
      aipGetMessageUnReadNum({}).then((res) => {
        this.resMsgReadNum = res.data;
      });
    },
    //清空消息:
    getClearMessage() {
      var that = this;
      Dialog.confirm({
        message: "此操作不会影响原帖相关内容,确定清空列表所有消息?",
      }).then(() => {
          // on confirm
          apiClearMessage({
            msgType: 0,
          }).then((res) => {
             if(res.code==200){
              that.$toast.success('已清空!')
              that.getMessageUnReadNum()
            }
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    //消息设置为已读
    getClearMessageUnReadNum(i) {
      var that = this;
      Dialog.confirm({
        message: "确定将列表的未读消息设置已读?",
      }).then(() => {
          // on confirm
          apiClearMessageUnReadNum({
            msgType: i,
          }).then((res) => {
            if(res.code==200){
              that.$toast.success('设置成功!')
              that.getMessageUnReadNum()
            }
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    getClearMessageUnReadNum2(i) {
      apiClearMessageUnReadNum({
            msgType: i,
          }).then((res) => {
          });
    },
    jumpPraiseList() {
      this.getClearMessageUnReadNum2(1)
      this.$router.push({
        path: "/pages/praiseList",
        query: {
          //传递参数
        },
      });
    },
    jumpSystemList() {
      this.getClearMessageUnReadNum2(3)
      this.$router.push({
        path: "/pages/systemMsgList",
        query: {
          //传递参数
        },
      });
    },
    jumpCommentList() {
      this.getClearMessageUnReadNum2(2)
      this.$router.push({
        path: "/pages/commentList",
        query: {
          //传递参数
        },
      });
    },
  },
  created() {},
  components: {
    [Switch.name]: Switch,
    [Dialog.name]: Dialog,
  },
};
</script>

<style scoped>
.deleStatus {
  font-size: 16px;
  font-weight: 500;
  color: #181818;
  text-align: center;
  height: 50px;
  line-height: 50px;
}
.deleImg {
  width: 13px;
  height: 13px;
}
.wrap {
  border-radius: 20px;
  min-height: 100vh;
  background-color: #fff;
  margin-top: 10px;
}
.item {
  height: 60px;
  border-bottom: 1px solid #e5e5e5;
  width: 95%;
  margin: 0 auto;
}
.leftIconWrap {
  font-size: 13px;
  font-weight: 400;
  color: #181818;
  float: left;
}
.icon {
  float: left;
  width: 40px;
  height: 40px;
  margin-right: 15px;
  margin-top: 10px;
}
.leftText {
  float: left;
  margin-top: 20px;
}
.rightIconWrap {
  float: right;
  margin-top: 20px;
}
.number {
  background: #ff4646;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 500;
  color: #ffffff;
  padding: 3px 8px;
  border-radius: 15px;
  margin-right: 10px;
}
.arrow {
  width: 5px;
  height: 9px;
}
.maskWrap {
}
.maskBg {
  width: 100%;
  min-height: 100vh;
  opacity: 0.35;
  background-color: #000;
  position: fixed;
  top: 0px;
}
.chooseNumWrap {
  width: 100%;
  background-color: #fff;
  position: fixed;
  bottom: 0px;
  border-radius: 20px 20px 0px 0px;
}
.optionsItem {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #eee;
  color: #000;
  font-size: 14px;
  text-align: center;
}
.dele {
  background-color: #eee;
  border-radius: 20px;
  width: 90%;
  margin: 5px auto;
  height: 40px;
  line-height: 40px;
}
</style>
